import { defineStore } from 'pinia'
import { store } from '../index'

export const useCommonStore = defineStore('common', {
  state: () => {
    return {
      formData: null
    }
  },
  getters: {
    getFormData(): any {
      const data = localStorage.getItem('formData')
      if (typeof data === 'string') {
        this.formData = JSON.parse(data)
      }
      return this.formData
    }
  },
  actions: {
    setFormData(value) {
      this.formData = value
      localStorage.setItem('formData', JSON.stringify(value))
    }
  }
})

export const useCommonStoreOut = () => {
  return useCommonStore(store)
}
